//
//  GYBuyDetailCell.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/3.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYBuyDetailCell.h"
#import "Head.h"
@interface GYBuyDetailCell ()
@property(nonatomic,strong)UILabel* titleLab;
@property(nonatomic,strong)UILabel* protypeLab;
@property(nonatomic,strong)UILabel* priceLab;
@property(nonatomic,strong)UILabel* areaLab;
@property(nonatomic,strong)UILabel* countLab;
@property(nonatomic,strong)UILabel* timeLab;
@property(nonatomic,strong)UILabel* creatTimeLab;
@property(nonatomic,strong)UIImageView* lineIV;
@property(nonatomic,strong)UILabel* collectLab;
@end

@implementation GYBuyDetailCell

#pragma mark setter getter
-(UIButton *)collectBtn
{
    if (!_collectBtn) {
        _collectBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        UIImage* iamge=[UIImage imageNamed:@"Star2"];
        UIImage* iamgeH=[UIImage imageNamed:@"Star"];
        _collectBtn.frame=WFCGRectMake(321, 30, iamge.size.width, iamge.size.height);
        [_collectBtn setBackgroundImage:iamge forState:UIControlStateNormal];
         [_collectBtn setBackgroundImage:iamgeH forState:UIControlStateSelected];
        
    }
    return _collectBtn;
}
-(UILabel *)collectLab
{
    if (!_collectLab) {
        _collectLab=[[UILabel alloc]initWithFrame:WFCGRectMake(318.5, 52, 375-320, 12)];
        _collectLab.text=@"收藏";
        _collectLab.font=SYSTEMFONT(11);
        _collectLab.textColor=Main_Color_LightGray;
        _collectLab.textAlignment=NSTextAlignmentLeft;
    }
    return _collectLab;
}
-(UIImageView *)lineIV
{
    if (!_lineIV) {
        _lineIV=[[UIImageView alloc] init];
        _lineIV.frame=WFCGRectMake( 290,24.5,WFCGFloatBackX(1), 48.5);
        _lineIV.backgroundColor=RGBACOLOR(151, 151, 151, 1);
    }
    return _lineIV;
}
-(UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab=[[UILabel alloc] init];
        _titleLab.textColor=Main_Color_Black;
        _titleLab.font=SYSTEMFONT(21);
       
    }
    return _titleLab;
}
-(UILabel *)protypeLab
{
    if (!_protypeLab) {
        _protypeLab=[[UILabel alloc] init];
        _protypeLab.textColor=Main_Color_Red;
        _protypeLab.textAlignment=NSTextAlignmentCenter;
        _protypeLab.font=SYSTEMFONT(10);
    }
    return _protypeLab;
}
-(UILabel *)priceLab
{
    if (!_priceLab) {
        _priceLab=[[UILabel alloc] init];
        _priceLab.textColor=RGBACOLOR(245, 166, 35, 1);
        _priceLab.font=SYSTEMFONT(17);
    }
    return _priceLab;
}

-(UILabel *)areaLab
{
    if (!_areaLab) {
        _areaLab=[[UILabel alloc] init];
        _areaLab.textColor=Main_Color_LightGray;
        _areaLab.font=SYSTEMFONT(14);
    }
    return _areaLab;
}

-(UILabel *)countLab
{
    if (!_countLab) {
        _countLab=[[UILabel alloc] init];
        _countLab.textColor=Main_Color_LightGray;
        _countLab.font=SYSTEMFONT(14);
    }
    return _countLab;
}


-(UILabel *)timeLab
{
    if (!_timeLab) {
        _timeLab=[[UILabel alloc] init];
        _timeLab.textColor=Main_Color_LightGray;
        _timeLab.font=SYSTEMFONT(14);
    }
    return _timeLab;
}
-(UILabel *)creatTimeLab
{
    if (!_creatTimeLab) {
        _creatTimeLab=[[UILabel alloc] init];
        _creatTimeLab.textColor=Main_Color_LightGray;
        _creatTimeLab.font=SYSTEMFONT(10);
        _creatTimeLab.textAlignment=NSTextAlignmentCenter;
    }
    return _creatTimeLab;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
     
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.protypeLab];
        [self.contentView addSubview:self.lineIV];
        [self.contentView addSubview:self.priceLab];
        [self.contentView addSubview:self.areaLab];
        [self.contentView addSubview:self.countLab];
        [self.contentView addSubview:self.timeLab];
        [self.contentView addSubview:self.creatTimeLab];
        [self.contentView addSubview:self.collectLab];
        [self.contentView addSubview:self.collectBtn];
    }
    return self;
}
-(void)setModel:(GYHomeBuyProductInfoModel *)model
{
    NSString* nameStr=model.name;
    if (nameStr.length>8) {
        nameStr=[nameStr substringToIndex:8];
    }
    _titleLab.text=nameStr;
    _protypeLab.text=_model.protypename;
    _priceLab.text=[NSString stringWithFormat:@"%ld-%ld元/%@",model.minprice,model.maxprice,@"只"];
    
    
    CGSize titleSize = [WFFunctions WFStrGetSize:_titleLab.text width:MAXFLOAT font:SYSTEMFONT(21)];
    _titleLab.frame=WFCGRectMake(12.5, 20, titleSize.width, titleSize.height);
    _titleLab.width=titleSize.width;
    
    
    CGSize proSize = [WFFunctions WFStrGetSize:_protypeLab.text width:MAXFLOAT font:SYSTEMFONT(10)];
    _protypeLab.frame=WFCGRectMake(12.5+titleSize.width+3, 25+3, proSize.width+5, proSize.height+2);
    _protypeLab.x=titleSize.width+WFCGFloatX(15.5);
    _protypeLab.width=proSize.width+5;
    _protypeLab.height=proSize.height+2;
    [WFFunctions WFUIaddbordertoView:_protypeLab radius:4 width:0.8 color:Main_Color_Red];
    _priceLab.frame=WFCGRectMake(12.5, 60, 200, 17);
    
    
    
    _areaLab.text=[NSString stringWithFormat:@"地区: %@",model.address];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_areaLab.text attributes:@{NSFontAttributeName: SYSTEMFONT(14)}];
    [attributedString addAttribute:NSForegroundColorAttributeName value:Main_Color_LightGray range:NSMakeRange(0, 3)];
    [attributedString addAttribute:NSForegroundColorAttributeName value:Main_Color_Gray range:NSMakeRange(3, _areaLab.text.length-3)];
    _areaLab.attributedText=attributedString;
    _areaLab.frame=WFCGRectMake(12.5, 103, 345, 14);
    
    _countLab.text=[NSString stringWithFormat:@"数量: %ld%@",model.count,@"只"];
    
    NSMutableAttributedString * CountattributedString = [[NSMutableAttributedString alloc] initWithString:_countLab.text attributes:@{NSFontAttributeName: SYSTEMFONT(14)}];
    [CountattributedString addAttribute:NSForegroundColorAttributeName value:Main_Color_LightGray range:NSMakeRange(0, 3)];
    [CountattributedString addAttribute:NSForegroundColorAttributeName value:Main_Color_Gray range:NSMakeRange(3, _countLab.text.length-3)];
    _countLab.attributedText=CountattributedString;
    _countLab.frame=WFCGRectMake(12.5, 103+20, 345, 14);
    
    
    _timeLab.text=[NSString stringWithFormat:@"到期时间: %@",@"15天"];
    
    NSMutableAttributedString * timeAttributedString = [[NSMutableAttributedString alloc] initWithString:_timeLab.text attributes:@{NSFontAttributeName: SYSTEMFONT(14)}];
    [timeAttributedString addAttribute:NSForegroundColorAttributeName value:Main_Color_LightGray range:NSMakeRange(0, 5)];
    [timeAttributedString addAttribute:NSForegroundColorAttributeName value:Main_Color_Gray range:NSMakeRange(5, _timeLab.text.length-5)];
    _timeLab.attributedText=timeAttributedString;
    _timeLab.frame=WFCGRectMake(12.5, 103+20+20, 345, 14);
    
    _creatTimeLab.text=model.time;
    
    CGSize timeSize = [WFFunctions WFStrGetSize:_creatTimeLab.text width:MAXFLOAT font:[UIFont systemFontOfSize:10]];
    _creatTimeLab.frame=WFCGRectMake(375-15-timeSize.width-5, 143, timeSize.width+5, 15);
    [WFFunctions WFUIaddbordertoView:_creatTimeLab radius:4 width:1 color:RGBACOLOR(229 ,227, 227, 1)];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    
    
}
@end
